﻿using System.Windows;
using System.Windows.Threading;
using Autofac;
using fc2editor.Common;
using fc2editor.Services;
using fc2editor.ViewModels;

namespace fc2editor
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            Application.Current.DispatcherUnhandledException +=
                new DispatcherUnhandledExceptionEventHandler(Current_DispatcherUnhandledException);

            InitializeComponent();

            DataContext = new MainViewModel(InitContainer());
        }

        void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            Logger.Write(e.Exception);
        }

        private IContainer InitContainer()
        {
            var builder = new ContainerBuilder();

            //builder.RegisterInstance<ICacheService>(new CacheService());
            builder.RegisterType<CacheService>().As<ICacheService>().SingleInstance();
            builder.RegisterType<FileService>().As<IFileService>().SingleInstance();
            builder.RegisterType<WeaponService>().As<IWeaponService>().SingleInstance();
            builder.RegisterType<AircraftService>().As<IAircraftService>().SingleInstance();

            builder.RegisterType<WeaponSelectorViewModel>().As<IWeaponSelectorViewModel>();

            return builder.Build();
        }
    }
}
